<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=\, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        background-color: #ccc;
      }

      #box {
        width: 920px;
        height: 920px;
        display: flex;
        flex-wrap: wrap;
        margin: 50px auto;
        background-color: #fff;
      }

      #box > div {
        flex: 300px;
        border: 2px solid;
      }

      .btn {
        cursor: pointer;
      }

      .active {
        background-color: cornsilk;
        /* border: 3px solid red !important; */
      }
    </style>
  </head>
  <body>
    <div id="box">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
      <div class="btn">抽象</div>
      <div class="item">6</div>
      <div class="item">7</div>
      <div class="item">8</div>
      <div class="item">9</div>
    </div>

    <script>
      // 按钮
      let btn = document.querySelector(".btn");
      // 奖品
      let jp = document.querySelectorAll(".item");

      btn.onclick = (e) => {
        let index = 0;
        let i = setInterval(() => {
          // 之前选中的 取消选中
          let selector = document.querySelector(".active");
          if (selector) {
            selector.classList.remove("active");
          }
          //   let index = Math.floor(Math.random() * 8);
          jp[index++].classList.add("active");
          if (index >= 8) {
            index = 0;
          }
        }, 30);

        setTimeout(() => {
          clearInterval(i);
        }, 3000);
      };
    </script>
  </body>
</html>
